import type { Module } from 'vuex'
import type { CurrentUserInfo, RootStateTypes } from '../interface'
import type UserInfo from '@jsjn/types/entity/UserInfo'
import type ClientChannel from '@jsjn/types/entity/ClientChannel'
import type OrgInfo from '@jsjn/types/entity/OrgInfo'
import { assignOwnProp } from '@jsjn/utils'

const currentUserInfo: Module<CurrentUserInfo, RootStateTypes> = {
    namespaced: true,
    state() {
        return {
            device: '',
            accountInfo: {} as UserInfo,
            clientInfo: {} as ClientChannel,
            instituInfo: {} as OrgInfo,
            loginInfo: {},
            departList: [],
            postList: [],
            roleList: [],
            roleModelList: [],
            roleDepartList: [],
            passwordNeedEdit: false,
            passwordNeedEditRemind: false
        }
    },
    mutations: {
        // 全量赋值
        setCurrentUserInfo(state, data: CurrentUserInfo) {
            const currentState = JSON.stringify(state)
            const nextState = JSON.stringify(data)
            if (currentState === nextState) return
            assignOwnProp(state, data)
        }
    },
    actions: {}
}

export default currentUserInfo
